
#include "stdafx.h"
#include "iocp_tcp_send_test1_protocol.h"

namespace stest
{
	
	 int sleepTime=10;
	 int sendBuffSize=10;
	 int isStop=0;
	myTcpClient *tcpc;
	int sendCount[1000];

	long iocpInit()
	{
		myIOCPNetworkConfigure sets;
		sets.postRecv_sum = 1;
		sets.recvBuffSize=8100;//8K
		sets.ioContext_AutoAddSum=200;
		sets.ioContext_AutoAddTimes = 2000;
		sets.workThreads_sum = 3;
		setNetworkConfig(sets);
		iocpNetworkInit();

		tcpc = new myTcpClient;
		tcpc->setEnableTcpKeepalive(1);
		return 1;

	}

	DWORD WINAPI thread_send(LPVOID argu)
	{
		int i=(int)argu;
		char *buff=new char[sendBuffSize];
		memset(buff,(char)(i+'A'),sendBuffSize);
		
		while (!isStop )
		{
			if(tcpc->isRuning())
			{
				tcpc->_send(buff,sendBuffSize);
				sendCount[i]++;
				Sleep(sleepTime);
			}else
			{
				break;
			}
		}
		delete []buff;
		return 1;
	}


	long iocpCreateThread(long icount)
	{
		ZeroMemory(sendCount,sizeof(sendCount));
		for (int i=0;i<icount;i++)
		{
			CreateThread(0,0,thread_send,(void*)i,0,0);
		}

		return 1;
	}


};

















